package com.csun.cmny.provider.device.sleepcare.entity.pojo;

import lombok.Data;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-02-23 11:00
 * @Description: the class sleep care body motion
 */
@Data
public class SleepCareBodyMotion {

    /**
     * 时间
     */
    private ArrayList<String> timeList;

    /**
     * 体动时间（单位:秒）
     */
    private ArrayList<Integer> bodyMotionList;

    // 最近体动次数
    public Integer getNowbodyMotion(){
        if(bodyMotionList.size() == 0) {
            return null;
        }
        return bodyMotionList.get(bodyMotionList.size()-1);
    }

    // 最后一次体动时间
    public String getLastActionTime(String date){

        if( bodyMotionList.size() == 0){
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String today = sdf.format(new Date());
        ArrayList<String> timeList1 = new ArrayList<String>();
        for(String time : timeList){
            int hours = Integer.parseInt(time.substring(0, 2));

            if(hours > 12){
                time = date + " " + time;
            }else{
                time = today + " " + time;
            }
            timeList1.add(time);
        }

        for(int i = bodyMotionList.size()-1 ; i >= 0 ; i--){
            int act = bodyMotionList.get(i);
            if(act > 0){
                return   timeList1.get(i);
            }
        }

        return timeList1.get(0);
    }
}
